﻿import request from '/@/utils/request';
enum Api {
  AddFlowSystemSGJK = '/api/flowSystemSGJK/add',
  DeleteFlowSystemSGJK = '/api/flowSystemSGJK/delete',
  UpdateFlowSystemSGJK = '/api/flowSystemSGJK/update',
  SaveFlowSystemSGJK = '/api/flowSystemSGJK/save',
  PageFlowSystemSGJK = '/api/flowSystemSGJK/page',
  ExportFlowSystemSGJK = 'api/flowSystemSGJK/export',
  ImportUrl= 'api/flowSystemSGJK/import',
  downLoadTemplate = 'api/flowSystemSGJK/TemplateDown',
  UploadImages = '/api/flowSystemSGJK/UploadImages',
}

//导出工程監工日誌打印
export const exportFlowSystemSGJKExcel=(params?:any)=>
	request({
		url:Api.ExportFlowSystemSGJK,
		method:'post',
		data:params,
		responseType: 'blob'
	});

// 增加工程監工日誌打印
export const addFlowSystemSGJK = (params?: any) =>
	request({
		url: Api.AddFlowSystemSGJK,
		method: 'post',
		data: params,
	});

// 删除工程監工日誌打印
export const deleteFlowSystemSGJK = (params?: any) => 
	request({
			url: Api.DeleteFlowSystemSGJK,
			method: 'post',
			data: params,
		});

// 编辑工程監工日誌打印
export const updateFlowSystemSGJK = (params?: any) => 
	request({
			url: Api.UpdateFlowSystemSGJK,
			method: 'post',
			data: params,
		});

// 保存工程監工日誌打印
export const saveFlowSystemSGJK = (params?: any) => 
	request({
			url: Api.SaveFlowSystemSGJK,
			method: 'post',
			data: params,
		});

// 分页查询工程監工日誌打印
export const pageFlowSystemSGJK = (params?: any) => 
	request({
			url: Api.PageFlowSystemSGJK,
			method: 'post',
			data: params,
		});

export const importUrl = () => {return Api.ImportUrl;};
export const downLoadTemplate = ()=>{return Api.downLoadTemplate ;};


	/**
	* 上传照片 
	*/
export const uploadImages = (params: any) =>
		uploadFileHandle(params, Api.UploadImages)

	export const uploadFileHandle = (params: any, url: string) => { 
	const formData = new window.FormData();
	formData.append('file', params.file);
	//自定义参数
	if (params.data) {
		Object.keys(params.data).forEach((key) => {
			const value = params.data![key];
			if (Array.isArray(value)) {
				value.forEach((item) => {
					formData.append(`${key}[]`, item);
				});
				return;
			}
			formData.append(key, params.data![key]);
		});
	}
	return request({
		url: url,
		method: 'POST',
		data: formData,
		headers: {
			'Content-type': 'multipart/form-data;charset=UTF-8',
			// ts-ignore
			ignoreCancelToken: true,
		},
	});
};
